package com.ets.common;

/*------------------------------------------------------------------------------
 System-wide <big><b>Formatter</b></big> class
 <br><br>
 @author D.Merkling - 1:33:38 PM - Aug 22, 2011
 <br><br>
 @version 1.0  
------------------------------------------------------------------------------*/
public abstract class Formatter
  {
   public static String formatPhone (String Phn)
     {
	  String inPhn  = Phn.trim();
	  String outPhn = "";
	  int    pos    = 0;
	  for (int i = 0; i < inPhn.length(); i++)
	    {
  	     if (isNumber(inPhn.charAt(i)) == true)
  	       {
  		    outPhn = outPhn + inPhn.charAt(i);
  		    pos++;
  		    if (pos == 3 || pos == 7)
  		      {
  		       outPhn = outPhn + "-";
  		       pos++;
  		      }
  	       }
	    }
	  if (pos != 12)
	    {
		 return "**BAD**";
	    }
	  return outPhn;
     }

   private static boolean isNumber (char ch)
     {
	  if ((ch == '0') || (ch == '1') || (ch == '2') || (ch == '3') || (ch == '4') ||
		  (ch == '5') || (ch == '6') || (ch == '7') || (ch == '8') || (ch == '9'))
	    {
		 return true;  
	    }
	  return false;
     }
  
   public static String formatZip (String zp)
     {
	  String inZp  = zp.trim();
	         inZp  = inZp.toUpperCase();
	  if (inZp.length() > 10)
	    {
		 return "**BAD**";
	    }
	  String outZp = "";
	  int    pos   = 0;
	  for (int i = 0; i < inZp.length(); i++)
	    {
		 if (isNumber(inZp.charAt(i)) == true)
		   {
			outZp = outZp + inZp.charAt(i);
			pos++;
            if ((pos == 5) && (inZp.length() == 5))
              {
               return outZp;	
              }
            if (pos == 5)
              {
   		       outZp = outZp + "-";
  		       pos++;
              }
		   }
	    }
	  if (pos != 10)
	    {
		 return "**BAD**";
	    }
	  return outZp;
     }
  }
